import {set,get} from "lodash-es"


export const pickData = (data:any,keys:[k:string,s?:string|string[]|((d:any) => any)][],type:"object"|"array"|Object = "object") => {
    const res:any = typeof type === 'string' ? (type == 'array' ? [] : {}) : type;
    for(const [k,t = k] of keys){
        let v;
        if(typeof t == 'function'){v = t(data)}
        else if(Array.isArray(t)){
            const sk = t.filter(k => get(data,k))[0];
            sk && (v = get(data,sk))
        }
        else{
            v = get(data,t)
        }
        if(v != undefined){
            type == 'array' ? res.push([k,v]) : set(res,k,v);
        }
    }
    return res;
}

